﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hisun.Models;
using Hisun.Controllers;
using System.Collections.Generic;

namespace Hisun.View.ReportQuery
{
    public partial class Report_ZYZXJHCBB_DETAIL : AbcPageBase
    {
        HisunDBDataContext db = new HisunDBDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string AccountPeriod = Request["AccountPeriod"].ToString();
                var IsValidString = from a in db.TABC_JS_AccountPeriods
                                    where a.会计期间ID == AccountPeriod
                                    select a;
                if (IsValidString.Count() == 0)
                {
                    Response.Write("<Script>alert('会计期间不存在，请检查输入是否正确')</Script>");
                    return;
                }
                else if (IsValidString.Count() == 1)
                {
                    int MyCenterID = Convert.ToInt32(Request["Centerid"].ToString());
                    string MyPIP = Request["PIPid"].ToString();
                    string IsPrinte = Request["IsPrinte"].ToString();
                    string CurrentUser = Session[ServerVars.sysSessionUserName].ToString();
                    CostReport MyReport = new CostReport();
                    string myHtmlReport = "";

                    myHtmlReport = MyReport.WriteExcel_Report_ZYZXJHCBB(MyCenterID, MyPIP, AccountPeriod, CurrentUser);

                    if (IsPrinte == "0")
                    {
                        Response.Redirect("/Report/UserReport/" + myHtmlReport + ".html");
                    }
                    else
                    {

                        HttpResponse response = HttpContext.Current.Response;
                        response.Clear();
                        response.WriteFile("/Report/UserReport/" + myHtmlReport + ".xls");
                        string httpHeader = "attachment;filename= ZYZXJHCBB-" + MyPIP + ".Xls";
                        response.AppendHeader("Content-Disposition", httpHeader);
                        response.Flush();   
                    
                    }


                }

            }
        }
    }
}
